﻿namespace KeRui.BLL
{
    using KeRui.DAL;
    using KeRui.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;

    public class CmsContentOwner
    {
        private readonly KeRui.DAL.CmsContentOwner dal = new KeRui.DAL.CmsContentOwner();

        public int Add(KeRui.Model.CmsContentOwner model)
        {
            return this.dal.Add(model);
        }

        public List<KeRui.Model.CmsContentOwner> DataTableToList(DataTable dt)
        {
            List<KeRui.Model.CmsContentOwner> list = new List<KeRui.Model.CmsContentOwner>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    KeRui.Model.CmsContentOwner item = new KeRui.Model.CmsContentOwner();
                    if (dt.Rows[i]["ID"].ToString() != "")
                    {
                        item.ID = int.Parse(dt.Rows[i]["ID"].ToString());
                    }
                    if (dt.Rows[i]["UserID"].ToString() != "")
                    {
                        item.UserID = int.Parse(dt.Rows[i]["UserID"].ToString());
                    }
                    item.UserName = dt.Rows[i]["UserName"].ToString();
                    if (dt.Rows[i]["SellerID"].ToString() != "")
                    {
                        item.SellerID = int.Parse(dt.Rows[i]["SellerID"].ToString());
                    }
                    item.SellerName = dt.Rows[i]["SellerName"].ToString();
                    if (dt.Rows[i]["ContentID"].ToString() != "")
                    {
                        item.ContentID = int.Parse(dt.Rows[i]["ContentID"].ToString());
                    }
                    item.ContentTitle = dt.Rows[i]["ContentTitle"].ToString();
                    if (dt.Rows[i]["OwnerType"].ToString() != "")
                    {
                        item.OwnerType = int.Parse(dt.Rows[i]["OwnerType"].ToString());
                    }
                    if (dt.Rows[i]["ModelID"].ToString() != "")
                    {
                        item.ModelID = int.Parse(dt.Rows[i]["ModelID"].ToString());
                    }
                    if (dt.Rows[i]["Cost"].ToString() != "")
                    {
                        item.Cost = int.Parse(dt.Rows[i]["Cost"].ToString());
                    }
                    if (dt.Rows[i]["Status"].ToString() != "")
                    {
                        item.Status = int.Parse(dt.Rows[i]["Status"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public int Delete(int ID)
        {
            return this.dal.Delete(ID);
        }

        public List<KeRui.Model.CmsContentOwner> GetList(int sellerid)
        {
            string strWhere = " WHERE SellerID =" + sellerid;
            string strOrder = "";
            int pageSize = -1;
            int pageIndex = -1;
            DataSet set = new KeRui.DAL.Common().GetList("CmsContentOwner", pageSize, pageIndex, strWhere, strOrder);
            return this.DataTableToList(set.Tables[0]);
        }

        public DataTable GetListJobApply(string tblName, int PageSize, int PageIndex, int SellerID)
        {
            string strWhere = " SellerID =" + SellerID;
            string strOrder = " ID DESC";
            KeRui.DAL.Common common = new KeRui.DAL.Common();
            return common.GetList(tblName, PageSize, PageIndex, strWhere, strOrder).Tables[0];
        }

        public DataTable GetListJobApplyByUID(string tblName, int PageSize, int PageIndex, int UserID)
        {
            string strWhere = " UserID =" + UserID;
            string strOrder = " ID DESC";
            KeRui.DAL.Common common = new KeRui.DAL.Common();
            return common.GetList(tblName, PageSize, PageIndex, strWhere, strOrder).Tables[0];
        }

        public KeRui.Model.CmsContentOwner GetModel(int ID)
        {
            return this.dal.GetModel(ID);
        }
    }
}

